from django.db import models
from django.utils.encoding import python_2_unicode_compatible

# Create your models here.
# 商品类别表:

class GoodCategory(models.Model):
    # 种类名
    cate_name = models.CharField("商品类别", max_length=20)

    class Meta:
        db_table = 'goods_goodcategory_tb'
        verbose_name = '商品种类'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.cate_name


# 商品表

class Good(models.Model):
    sku_name = models.CharField("商品名", max_length=100)
    price = models.DecimalField("价格", max_digits=13,decimal_places=2)
    selling_price = models.DecimalField("售价", max_digits=13,decimal_places=2)
    img = models.CharField("图片", max_length=200)
    title = models.CharField("标题", max_length=30)
    instruction = models.TextField("商品介绍", max_length=2000)
                                            # 默认为零
    count = models.IntegerField("商品销量", default=0)
    stock = models.IntegerField("商品库存", default=0)
    cate = models.ForeignKey(to=GoodCategory, on_delete=models.CASCADE, verbose_name="商品类别")
    online = models.BooleanField("是否在售", default=True)


    class Meta:
        db_table = 'goods_good_tb'
        verbose_name = "商品信息表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.sku_name


# 商品图片表

class GoodImg(models.Model):
    img = models.CharField("图片地址", max_length=200)
    title = models.CharField("图片描述", max_length=20, null=True)
    good = models.ForeignKey(to=Good, on_delete=models.CASCADE, verbose_name='商品')

    class Meta:
        db_table = "goods_goodimg_tb"
        verbose_name_plural = '商品图片表'

    def __str__(self):
        return self.good.sku_name


# 轮播图表

class Carousel(models.Model):
    imgPath = models.CharField("轮播图地址", max_length=100)
    describes = models.CharField("描述信息", max_length=100)

    class Meta:
        db_table = "goods_carousel_tb"
        verbose_name_plural = "轮播图"

    def __str__(self):
        return "轮播图%d"%self.id











